
//
//  DCBestBeautyShopCell.m
//  CDDStoreDemo
//
//  Created by 陈甸甸 on 2017/12/7.
//  Copyright © 2017年 RocketsChen. All rights reserved.
//

#import "DCBestBeautyShopCell.h"
#import "DCGroupImageCell.h"
#import "DCStoresRecommendHeaderView.h"

@interface DCBestBeautyShopCell()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

/* collectionView */
@property (strong , nonatomic)UICollectionView *collectionView;
@property (strong, nonatomic)  DCStoresRecommendHeaderView *topTitleView;

@end

static NSString *const DCGroupImageCellID = @"DCGroupImageCell";

@implementation DCBestBeautyShopCell





- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setUpAllChildView];
    }
    return self;
}

- (void)setUpAllChildView{
    WEAKSELF
    self.topTitleView = [[DCStoresRecommendHeaderView alloc]init];
    self.topTitleView.headRecommendLabel.text = @"最美美店";
    [self addSubview:self.topTitleView];
    [self.topTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.left.right.mas_equalTo(self);
        make.height.mas_equalTo(35);
    }];
    
    UICollectionViewFlowLayout *dcFlowLayout = [UICollectionViewFlowLayout new];
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:dcFlowLayout];
    dcFlowLayout.minimumLineSpacing = dcFlowLayout.minimumInteritemSpacing = 0;
    dcFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _collectionView.showsHorizontalScrollIndicator = NO;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_collectionView];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    [_collectionView registerClass:[DCGroupImageCell class] forCellWithReuseIdentifier:DCGroupImageCellID];
        
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.topTitleView.mas_bottom).with.offset(10);
        make.left.right.mas_equalTo(self);
        make.bottom.mas_equalTo(self).with.offset(-10);
    }];
}

#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return BeastBeautyShopArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DCGroupImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:DCGroupImageCellID forIndexPath:indexPath];
    NSString *groupIamgeUrl = BeastBeautyShopArray[indexPath.row];
    cell.groupImageUrl = groupIamgeUrl;
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(_collectionView.dc_height * 1.3, _collectionView.dc_height);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"哪个热门商品%ld",indexPath.row);
}
@end
